package demo;

import java.util.Scanner;

public class SimpleCalculator {
    public static void main(String[] args) {
        Scanner  sc = new Scanner(System.in);
        System.out.println("请输入第一个数字：");
        double num1 = sc.nextDouble();
        System.out.println("请输入运算符号(+、-、*、/)：");
        char op = sc.next().charAt(0);
        System.out.println("请输入第二个数字：");
        double num2 = sc.nextDouble();
        double  result = calculate(num1, op, num2);
        while (result == -1) {
            System.out.println("请输入运算符号(+、-、*、/)：");
            op = sc.next().charAt(0);
            result = calculate(num1, op, num2);
        }
        System.out.println("计算结果为：" + result);
    }
    public static double calculate(double num1, char op, double num2) {
        double result = 0;
        switch (op) {
            case '+':
                result = num1 + num2;
                break;
            case '-':
                result = num1 - num2;
                break;
            case '*':
                result = num1 * num2;
                break;
            case '/':
                result = num1 / num2;
                break;
            default:
                System.out.println("输入的运算符有误！");
                return -1;
        }
        return result;
    }
}
